package com.wb.dao;

import java.util.List;

import org.hibernate.Session;

import com.wb.model.Post;
import com.wb.util.HibernateUtil;

public class PostDao {
	 
	 public void save(Post p){
		 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 session.save(p);
		 session.getTransaction().commit();
	 }
	 public void update(Post p){
		 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 session.update(p);
		 session.getTransaction().commit();
	 }
	public List listUsers(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 List result = session.createQuery("from Post").list();
		 session.getTransaction().commit();
		 return result;
	}
	
	public Post get(int id){
			Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		Post p = (Post) session.load(Post.class, id);
		 session.getTransaction().commit();
		 return p;
	}
	public void delete(Post p){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		session.delete(p);
		 session.getTransaction().commit();
	}
	

	
}
